package com.dc2013.adapter;

import java.util.ArrayList;

import com.dc2013.followme.ImageItem;
import com.dc2013.followme.ListItem;
import com.dc2013.followme.R;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class MainAdapter extends BaseAdapter 
{

	Context context;
	private LayoutInflater inflater;
	private int layout;
	ArrayList<ListItem> main_ArrayList;
	ViewHolder holder;
	
	public MainAdapter(Context context,int layout,ArrayList<ListItem> main_ArrayList)
	{
		this.context = context;
		this.layout = layout;
		this.main_ArrayList = main_ArrayList;
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
	}

	@Override
	public int getCount() 
	{
		return main_ArrayList.size();
	}

	@Override
	public Object getItem(int position)
	{
		return main_ArrayList.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		
		if(convertView == null)
		{
			convertView = inflater.inflate(layout,parent,false);
			holder = new ViewHolder();
			holder.pager =(ViewPager)convertView.findViewById(R.id.main_pager);
			holder.subjTextView = (TextView)convertView.findViewById(R.id.main_subject_tv);
			holder.likeButton = (ImageButton)convertView.findViewById(R.id.main_like_btn);
			holder.commentTextView = (TextView)convertView.findViewById(R.id.main_comment_tv);
			holder.shareButton =(ImageButton)convertView.findViewById(R.id.main_share_btn);
			
			
			//set하는부분은 서버에서 받아와서?하는거라서 남겨둠
			holder.likeButton.setOnClickListener(new OnClickListener() 
			{
				
				@Override
				public void onClick(View v)
				{
					
					
				}
			});
			
			holder.shareButton.setOnClickListener(new OnClickListener() 
			{
				
				@Override
				public void onClick(View v) 
				{
					
					
				}
			});
			
			convertView.setTag(holder);
			
			
		}
		
		else
			holder = (ViewHolder)convertView.getTag();
		
		
		
		
		return convertView;
	}
	
	private static class ViewHolder
	{
		ViewPager pager;
		TextView subjTextView,commentTextView;
		ImageButton likeButton,shareButton;
		
	}
	

}
